package com.czxy.changgou3.com.czxy.changgou3.mapper;

import com.czxy.changgou3.pojo.Specification;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author zhangmengxiang1@itcast.cn
 * @version 1.0
 * @date 2020/4/22
 */
@org.apache.ibatis.annotations.Mapper
public interface SpecificationMapper extends Mapper<Specification> {

    //查询指定分类的所有规格，同时还要查询规格对应的所有规格选项。

    @Select("select * from tb_specification where category_id = #{categoryId} ")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "specName", column = "spec_name"),
            @Result(property = "categoryId", column = "category_id"),
            @Result(property = "options", many = @Many(select = "com.czxy.changgou3.com.czxy.changgou3.mapper.SpecificationOptionMapper.findAll"), column = "id")
    })
    public List<Specification> findAll(@Param("categoryId") Integer categoryId);
}

